<?php

namespace App\Http\Controllers\Home;

use App\Http\Controllers\Controller;
use App\Models\Business;
use App\Models\Stamps;
use Illuminate\Http\Request;

class StampsController extends CommonController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {

        $page = !$request['page'] ? $request['page'] : 1;
        $start = ($page - 1) * self::$totalList;

        $lists = Stamps::where('status', 1)->orderBy('id', 'desc')->offset($start)->limit(self::$totalList)->get();
        $totalCount = Stamps::where('status', 1)->count();

        return response()->json(['status' => 1, 'data' => ['list' => $lists, 'totalCount' => $totalCount]]);
    }

    /**
     * Notes:详情
     * User: Administrator
     * Date: 2023/10/9
     * Time: 18:33
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function read(Request $request)
    {
        $id = $request['id'];
        $row_info = Stamps::where('status', 1)->find($id);
        if (!$row_info) {
            return response()->json(['status' => 0, 'msg' => '参数错误']);
        }

        if (count($row_info->pics) > 0) {
            $row_info->pics = array_map('newPic', $row_info->pics);
        }

        return response()->json(['status' => 1, 'data' => $row_info]);
    }
}
